package com.czy.booktest02.demos.api.v1;

import com.czy.booktest02.demos.common.dtos.ResponseResult;
import com.czy.booktest02.demos.pojo.bo.AccountUserBo;
import com.czy.booktest02.demos.pojo.dto.CartDto;
import com.czy.booktest02.demos.service.ShoppingCartService;
import com.czy.booktest02.demos.utils.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    ShoppingCartService shoppingCartService;
    @PostMapping("/addToCart")
    public ResponseResult addCart(@RequestBody CartDto cartDto){
        return shoppingCartService.addCart(cartDto);
    }


    @GetMapping("/showCart")
    public ResponseResult showCart(){
        return shoppingCartService.showCart();
    }

    /**
     * 加减商品数量
     */
    @PostMapping("/addOrDecBook")
    public ResponseResult addOrDecBook(@RequestBody CartDto cartDto){
        return shoppingCartService.addOrDecBook(cartDto);
    }

    /**
     * 删除购物车项
     */
    @PostMapping("/deleteCartItem")
    public ResponseResult deleteCartItem(@RequestParam("ids")List<Integer> ids){
        return shoppingCartService.deleteCartItem(ids);
    }

}
